package cn.yunhe.interceptor;

import cn.yunhe.control.AdminAction;
import cn.yunhe.entity.Admin;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import java.util.Map;

public class AdminInterceptor extends MethodFilterInterceptor {
    @Override
    protected String doIntercept(ActionInvocation invocation) throws Exception {
        Map session = invocation.getInvocationContext().getSession();
        Map request = (Map) invocation.getInvocationContext().get("request");
        Admin admin = (Admin) session.get("admin");
        if (admin == null) {
            request.put("result", "登录名已失效,<a href='login.jsp'>去登陆</a>");
            return "error";
        } else {
            return invocation.invoke();
        }
    }
}
